<?php

/**
 * @author Martin Pernica
 * @copyright 2009
 */

abstract class ErrorHandler
{
    /**
     * ErrorHandler::Initialize()
     *
     * @return
     */
    public static function Initialize()
    {
        set_error_handler(array("ErrorHandler", "HandleError"), E_ALL);
        set_exception_handler(array("VException", "_throw"));
        //register_shutdown_function (array ("ErrorHandler", "HandleError"), '1', __FUNCTION__);
    }

    /**
     * ErrorHandler::Uninitialize()
     *
     * @return
     */
    public static function Uninitialize()
    {
        restore_error_handler();
        restore_exception_handler();
    }

    /**
     * ErrorHandler::HandleError()
     *
     * @param mixed $errno
     * @param mixed $errstr
     * @param mixed $errfile
     * @param mixed $errline
     * @param mixed $errcontext
     * @return
     */
    public static function HandleError($errno, $errstr, $errfile = '', $errline = 0)
    {
		if($errno == 1 || $errno == 2 || $errno == 4 || $errno == 16 || $errno == 32 || $errno == 64 || $errno == 128 || $errno == 256 || $errno == 512 || $errno == 2048 || $errno == 8192 || $errno == 4096){
        throw new VException($errstr, $errno, $errfile, $errline);
        //die();
        }elseif(($errno == 8 || $errno == 1024) && System::$Debug){
			echo '<p class="error_notice">'.$errstr.'</p>';
        }
    }
}

?>